package com.iflytek.uoamp.agent.common.util;

import java.io.File;

public class DirectoryControl {
	
	/**
	 * makdirs
	 * */
	public static void makdir(String dir){
		File cdir = new File(dir);
		if(!cdir.exists()){
			cdir.mkdirs();
		}
	}
	
	
	public static void delFile(String path){
		File file = new File(path);
		if (!file.exists()) {
			return;
		}
		file.delete();
	}
	
	/**
	 * delete all file
	 * */
	public static void delAllFile(String path) {

		File file = new File(path);
		if (!file.exists()) {
			return;
		}
		if (!file.isDirectory()) {
			file.delete();
			return;
		}
		String[] tempList = file.list();
		File temp = null;
		for (int i = 0; i < tempList.length; i++) {
			if (path.endsWith(File.separator)) {
				temp = new File(path + tempList[i]);
			} else {
				temp = new File(path + File.separator + tempList[i]);
			}
			if (temp.isFile()) {
				temp.delete();
			}
			if (temp.isDirectory()) {
				delAllFile(path + "/" + tempList[i]);
			}
		}

		if (!path.endsWith(File.separator)) {
			file.delete();
		}
	}
}
